<?php
namespace Admin\Controller;
use Common\Controller\AdminController;

/**
 * 项目基础信息维护
 * Class JsBaseInfoController
 * @package Admin\Controller
 */
class JsBaseInfoController extends AdminController{
	/**
	 * 列表_index
	 * @param string $where 查询条件，必须是字符串型
	 */
	private function _Inde($where = ""){
		$where = "pid > 0".$where;
		$list = $this->getList('*', 'js_base', $where, 'sort desc');
		$this->assign('list', $list);
	}

	/**
	 * 添加
	 */
	private function _Add(){
		if(IS_POST){
			$_POST['sort'] = $_POST['set_sort'];
			$_POST['status'] = $_POST['set_status'];
			unset($_POST['set_sort']);
			unset($_POST['set_status']);
			return $this->updateData($_POST, 'js_base');
		}
	}

	/**
	 * 获得编辑的信息
	 * @return bool
	 */
	private function _EditGet(){
		$info = $this->getInfo('*', 'js_base', array('id' => I('get.id', 0, 'intval')));
		if($info){
			$data['info'] = $info;
			$data['status'] = 1;
		}else{
			$data['info'] = '数据不存在';
			$data['status'] = 0;
		}
		return $data;
	}
	/**
	 * 编辑信息保存
	 * @return bool
	 */
	private function _EditSet(){
		$_POST['sort'] = $_POST['set_sort'];
		$_POST['status'] = $_POST['set_status'];
		unset($_POST['set_sort']);
		unset($_POST['set_status']);
		$result = $this->updateData($_POST, 'js_base',2);
		return $result;
	}

	/**
	 * 删除
	 */
	private function _Del(){
		$result = $this->deleteData('id=' . I('get.id', 0, 'intval'), 'js_base');
		return $result;
	}

	private function _setStatus(){
		$status = I('get.status', 0, 'intval');
		$result = M("js_base")->where('id=' . I('id', 0, 'intval'))->setField('status', ($status == 1 ? 0 : 1));
		return $result;
	}



	/**
	 * 实验室信息_index type = 'sysxx'
	 */
	public function sysxxIndex(){
		$where = " and type = 'sysxx'";
		$this->_Inde($where);
		$this->display();
	}
	/**
	 * 实验室信息_index 添加
	 */
	public function sysxxAdd(){
		return $this->_Add();
	}
	/**
	 * 实验室信息_index 编辑
	 */
	public function sysxxEdit(){
		if(IS_POST){
			//保存编辑信息
			$result = $this->_EditSet();
			$this->returnResult($result);
		}else{
			//编辑信息时显示数据
			$data = $this->_EditGet();
			$this->ajaxReturn($data);
		}
	}
	/**
	 * 实验室信息_index 删除
	 */
	public function sysxxDel(){
		$result = $this->_Del();
		$this->returnResult($result);
	}
	/**
	 * 实验室信息_index 设置状态
	 */
	public function sysxxSetStatus(){
		$result = $this->_setStatus();
		$this->returnResult($result);
	}

}